﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using PhatPhucLoc.util;
using PhatPhucLoc.model;
using System.Data.SqlClient;

namespace PhatPhucLoc.dao
{
    class HoaDonDAO
    {
        public static DataTable GetAll()
        {
            return DataUtil.executeStore("sp_HoaDon_GetAll", null);
        }

        public static DataTable GetByID(string id)
        {
            return DataUtil.executeStore("sp_HoaDon_GetByID", null);
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("id", SqlDbType.Int);
            param[0].Value = id;
        }

        public static String Insert(HoaDonModel _model)
        {
            SqlParameter[] param = new SqlParameter[3];
            int i = 0;
            param[i] = new SqlParameter("TongTien", SqlDbType.NVarChar);
            param[i++].Value = _model.TongTien;
            param[i] = new SqlParameter("MaKhachHang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaKhachHang;
            param[i] = new SqlParameter("@Output", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;
            DataUtil.executeNonStore("sp_HoaDon_Insert", param);
            return param[i].Value.ToString();

        }

        public static Boolean Update(HoaDonModel _model)
        {
            SqlParameter[] param = new SqlParameter[3];
            int i = 0;
            param[i] = new SqlParameter("ID", SqlDbType.NVarChar);
            param[i++].Value = _model.Id;
            param[i] = new SqlParameter("TongTien", SqlDbType.NVarChar);
            param[i++].Value = _model.TongTien;
            param[i] = new SqlParameter("MaKhachHang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaKhachHang;
            return DataUtil.executeNonStore("sp_HoaDon_Update", param);
        }

    }
}
